/**
 * 公共方法
 */

/**
 * 异步提交表单
 * @param {UI Element}   form     表单元素
 * @param {Function} callback 异步提交的回调函数
 */
function FormSubmit(form, callback) {
    //showLoadingMsg("正在努力地请求服务端,请稍后...");
    $.ajax({
        url: form.action,
        type: form.method,
        data: $(form).serialize(),
        success: function (result) {
            //hideLoadingMsg();
            callback(result);
        },
        error: function (result) {
            //hideLoadingMsg();
            //alert("提交表单失败："+result);
            _showInfoMessage("操作失败。", 'error');
        }
    });
}

//提示消息
function _showInfoMessage(title,type)
{
  //title 显示标题
  //type 提示类型 info, succsee,error 
  $.pnotify({
      title: title,
      type: type
  });
  //text 内容
  //width 宽度
}
function showLoadingMsg(msg, position, isautohide, timeout) {
    var loadpanel = $("#loadpanel");
    if (loadpanel.length == 0) {
        loadpanel = $("<div id=\"loadpanel\" class=\"loadingpanel\"/>").appendTo("body");
    }
    loadpanel.html("<img src='../../assets/img/icon/indicator_remembermilk_orange.gif' style='vertical-align:middle;margin-right:10px;' alt=''/><span>" + msg + "</span>");
    if (!position) {
        position = { right: 20, top: 3 };
    }
    loadpanel.css(position).show();
    if (isautohide) {
        showLoadTipTimerId = setTimeout(hideLoadingMsg, timeout);
    }
}
function hideLoadingMsg() {
    var loadpanel = $("#loadpanel");
    if (loadpanel.length > 0) {
        loadpanel.hide();
    }
}
var showErrorTipTimerId;
var showLoadTipTimerId;
var msg;
function showErrorTip(msg, position, isautohide, timeout) {

    var errorpanel = $("#errorpanel");
    if (errorpanel.length == 0) {
        errorpanel = $("<div id=\"errorpanel\" class=\"errorpanel\"/>").appendTo("body");
    }
    if (errorpanel.css("display") != "none") {
        errorpanel.find(">dt").append("<dl>" + msg + "</dl>");
        if (showErrorTipTimerId) {
            window.clearTimeout(showErrorTipTimerId);
        }
    }
    else {
        errorpanel.html("<dt><dl>" + msg + "</dl></dt>");
        if (!position) {
            position = { right: 20, top: 3 };
        }
        errorpanel.css(position).fadeIn();
    }
    if (isautohide) {
        showErrorTipTimerId = setTimeout(hideErrortip, timeout);
    }

}
function hideErrortip() {
    var errorpanel = $("#errorpanel");
    if (errorpanel.length > 0) {
        errorpanel.fadeOut();
    }
}
Date.prototype.Format = function (format) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "H+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "w": "0123456".indexOf(this.getDay()),
        "S": this.getMilliseconds()
    };
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
      RegExp.$1.length == 1 ? o[k] :
        ("00" + o[k]).substr(("" + o[k]).length));
    }
    return format;
};
